package com.binvshe.binvshe.organization;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.binvshe.binvshe.R;
import com.binvshe.binvshe.account.utils.FragmentUtils;
import com.binvshe.binvshe.common.http.ListDataRequestListener;
import com.binvshe.binvshe.common.http.MyHttpRequest;
import com.binvshe.binvshe.common.http.UrlCenter;
import com.binvshe.binvshe.organization.entity.OrgTypeEntity;
import com.binvshe.binvshe.organization.orgtype.SelectTypeFragment;
import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.framework.httprequest.IHttpRequest;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/9/18
 */
public class SearchClubActivity extends BaseActivity {

    @Bind(R.id.editClubName)
    EditText editClubName;
    @Bind(R.id.btnCancel)
    Button btnCancel;
    private String searchKey = null;//搜索的关键字

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        initSearch();
        initTitle();
        initView();
    }

    private void initView() {
        FragmentUtils.replaceFragment(getSupportFragmentManager(),R.id.frlytTypeList, SearchTypeFragment.newInstance());
    }

    public static void start(Context context) {
        Intent starter = new Intent(context, SearchClubActivity.class);
        context.startActivity(starter);

    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.act_club_search, container, false);
    }

    private void initTitle() {
        getCustomToolbar().setVisibility(View.GONE);

    }

    private void initSearch() {
        editClubName.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    searchKey = editClubName.getText().toString();
                    if (!TextUtils.isEmpty(searchKey)) {
                        ClubSearchResultActivity.start(SearchClubActivity.this
                                , ClubSearchResultActivity.USE_KEY, searchKey);
                    }
                    return true;
                }
                return false;
            }
        });
    }



    @OnClick(R.id.btnCancel)
    public void onClick() {
        this.finish();
    }

}
